<template>
  <el-form :inline="true" :model="formData" class="demo-form-inline">
    <el-form-item v-for="(item,key) in formFields" :label="item.label" :key="key">
      <template v-if="item.type == 'input'">
        <my-input v-model="formData[item.prop]" suffix-icon="el-icon-search"></my-input>
      </template>
      <template v-else-if="item.type == 'select'">
        <my-select v-model="formData[item.prop]" :options="item.options" :dict="item.dict" :url="item.url"></my-select>
      </template>
      <template v-else-if="item.type == 'date'">
        <my-date v-model="formData[item.prop]"></my-date>
      </template>
      <template v-else-if="item.type == 'radio'">
        <my-radio-button :options="item.options" :dict="item.dict" :url="item.url" v-model="formData[item.prop]"></my-radio-button>
      </template>
    </el-form-item>
    <el-form-item>
      <my-async-button type="primary" @search="handleSearch">查询</my-async-button>
      <my-button @click="handleClear">重置</my-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    /** 查询表单,根据传入参数自动生成表单 **/
    name: "my-search-form",
    props:{
      /** 查询字段 **/
      formFields: {
        type: Array,
        default: ()=>{
          return [];
        }
      }
    },
    data(){
      return{
        formData:{}
      }
    },
    methods:{
      /** 查询 **/
      handleSearch() {
        this.$emit('search',this.formData)
      },
      /** 重置 **/
      handleClear(){
        this.formData = {};
        this.$emit('clear')
      }
    }
  }
</script>

<style scoped>

</style>
